<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>到货验收--材料设备进场检验报告form</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/jquery.boot.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
    <script type="text/javascript" src="${re.contextPath}/pageoffice.js" id="po_js_main"></script>
</head>
<style>
    .windows {
        background-color: #f8f8f8;
    }
    .popUp {
        width: 90%;
    }
    .tableSelectBar>.layui-form input{
        display: none!important;
    }
    .tableSelectBar>.layui-form button{
        display: none!important;
    }
</style>

<body>
<div class="windows">

    <div class="popUp whitebg">
        <div class="popUpTitle ft24 bold">材料设备进场检验报告</div>
        <div class="clearfix mt10">
            <span class="fl">SDZZ-QR023</span>
            <span class="fr">CLJY${orderCode}
        </div>
        <div class="popUpBox book">

            <form action="" class="layui-form addform">

                <div class="popUpBox acceptance">
                    <table>
                        <tr>
                            <td style="border: 1px solid #CCCCCC;width: 20%;">工程名称</td>
                            <td style="border: 1px solid #CCCCCC;width: 40%;">
                                <input type="hidden" name="spfPrjid" value="${spf_prjid}">
                                <input type="hidden" name="fileInd" value="${ind}">
                                <input type="hidden" name="spfStaid" value="${spf_staid}">
                                <input type="hidden" name="spfMilid" value="${spf_milid}">
                                <input type="hidden" name="projectName" value="${pdto.projectName}">
                                <input type="hidden" name="spfFilecode" value="${spfFilecode}">
                                <input type="hidden" name="bfcId" value="27">
                                <input type="hidden" name="orderCode" value="${orderCode}">
                                <input type="hidden" name="fbCode" value="${fbCode}">
                                <input type="hidden" name="pcId" value="${pcId}">
                                <input type="hidden" name="wjNum" value="21">
                                <input type="text" name="spfF1" id="spfF1" value="${pdto.projectName}"
                                       lay-verify="spfF1"
                                       style="width: 100%;">
                            </td>
                            <td style="border: 1px solid #CCCCCC;width: 10%;text-align: center;">监理单位</td>
                            <td colspan="2" style="border: 1px solid #CCCCCC;width: 30%; text-align: left;">
                                <input type="text" style="width: 250px;" name="spfF2"
                                       value="${pdto.supervisorCompanyName}" lay-verify="spfF2">
                            </td>
                        </tr>
                        <tr>
                            <td style="border: 1px solid #CCCCCC;width: 20%;">业主单位</td>
                            <td style="border: 1px solid #CCCCCC;width: 40%;">
                                <input type="text" name="spfF3" lay-verify="spfF3" value="${pdto.owerCompany}">
                            </td>
                            <td style="border: 1px solid #CCCCCC;width: 10%; text-align: center;">承建单位</td>
                            <td colspan="2" style="border: 1px solid #CCCCCC;width: 30%;">
                                <input type="text" name="spfF4" lay-verify="spfF4" value="${cj}">
                            </td>
                        </tr>
                        <tr>
                            <table id="tabledata">
                                <thead>
                                <tr>
                                    <td  rowspan="2" style="width: 5%; border: 1px solid #CCCCCC;" align="center">
                                     选择
                                    </td>
                                    <td rowspan="2" style="width: 5%; border: 1px solid #CCCCCC;" align="center">
                                        序号
                                    </td>
                                    <td colspan="6" style="width: 10%; border: 1px solid #CCCCCC;text-align: center">
                                        合同清单
                                    </td>

                                    <td colspan="2" style="width: 10%;border: 1px solid #CCCCCC;" align="center">
                                        质检证明
                                    </td>
                                    <td rowspan="2" style="width: 20%;border: 1px solid #CCCCCC;" align="center">
                                        实际情况
                                    </td>
                                    <td rowspan="2" style="width: 10%;border: 1px solid #CCCCCC;" align="center">
                                        操作
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 10%; border: 1px solid #CCCCCC;text-align: center">
                                        区域
                                    </td>
                                    <td style="width: 10%; border: 1px solid #CCCCCC;text-align: center">
                                        名称
                                    </td>
                                    <td style="width: 10%; border: 1px solid #CCCCCC;text-align: center">
                                        品牌
                                    </td>
                                    <td style="width: 10%;border: 1px solid #CCCCCC;text-align: center">
                                        规格/型号
                                    </td>
                                    <td style="width: 10%;border: 1px solid #CCCCCC;text-align: center">
                                        数量
                                    </td>
                                    <td style="width: 10%;border: 1px solid #CCCCCC;text-align: center">
                                        单位
                                    </td>
                                    <td style="width: 10%;border: 1px solid #CCCCCC;text-align: center">
                                        合格证
                                    </td>
                                    <td style="width: 10%;border: 1px solid #CCCCCC;text-align: center">
                                        自检报告
                                    </td>
                                </tr>
                                </thead>
                                <tbody>
<#--                                <#list htlist as vo>-->
<#--                                    <tr>-->
<#--                                        <td style="width: 5%; border: 1px solid #CCCCCC;" align="center">-->
<#--                                            <input align="center" type="text" class="fdata" value="${vo[0]}"-->
<#--                                                   style="text-align: center" name="formDataList[${vo_index}].data1"-->
<#--                                                   iname="data1">-->
<#--                                            <input type="hidden" class="fdata" name="formDataList[${vo_index}].tableRow"-->
<#--                                                   iname="tableRow" value="7">-->
<#--                                            <input type="hidden" class="fdata" name="formDataList[${vo_index}].tableCos"-->
<#--                                                   iname="tableCos" value="8">-->
<#--                                            <input type="hidden" class="fdata"-->
<#--                                                   name="formDataList[${vo_index}].tableIndex" iname="tableIndex"-->
<#--                                                   value="1">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%; border: 1px solid #CCCCCC;">-->
<#--                                            <input type="text" class="fdata" style="text-align: center"-->
<#--                                                   name="formDataList[${vo_index}].data2" iname="data2"-->
<#--                                                   value="${vo[1]}">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%; border: 1px solid #CCCCCC;">-->
<#--                                            <input type="text" class="fdata" style="text-align: center"-->
<#--                                                   name="formDataList[${vo_index}].data3" iname="data3"-->
<#--                                                   value="${vo[2]}">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%;border: 1px solid #CCCCCC;">-->
<#--                                            <input type="text" class="fdata" style="text-align: center"-->
<#--                                                   name="formDataList[${vo_index}].data4" iname="data4"-->
<#--                                                   value="${vo[3]}">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%;border: 1px solid #CCCCCC;">-->
<#--                                            <input type="text" class="fdata" name="formDataList[${vo_index}].data5" style="text-align: center"-->
<#--                                                   iname="data5" value="${vo[4]}">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%;border: 1px solid #CCCCCC;" align="center">-->
<#--                                            <input type="text" class="fdata" name="formDataList[${vo_index}].data6" style="text-align: center"-->
<#--                                                   iname="data6">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%;border: 1px solid #CCCCCC;" align="center">-->
<#--                                            <input type="text" class="fdata" name="formDataList[${vo_index}].data7" style="text-align: center"-->
<#--                                                   iname="data7">-->
<#--                                        </td>-->
<#--                                        <td style="width: 20%;border: 1px solid #CCCCCC;" align="center">-->
<#--                                            <input type="text" class="fdata" name="formDataList[${vo_index}].data8" style="text-align: center"-->
<#--                                                   iname="data8">-->
<#--                                        </td>-->
<#--                                        <td style="width: 10%;border: 1px solid #CCCCCC;" align="center">-->
<#--                                            <img src="${re.contextPath}/plugin/common/images/19@2x.png"-->
<#--                                                 style="width: 22px;" onclick="deleteStr(this)" alt="">-->
<#--                                        </td>-->
<#--                                    </tr>-->
<#--                                </#list>-->
                                </tbody>
                            </table>
                        </tr>

                    </table>
                    <table style="border: none;">
                        <tr style="border: none;">
                            <td style="border: none;width: 90%;" colspan="3"></td>
                            <td style="border: none;width: 10%;">
                                <img src="${re.contextPath}/plugin/common/images/57@2x.png" alt=""
                                     onclick="formAct.addOneLine()" style="width: 40px;padding-left: 39px;padding-top: 10px;">
                            </td>
                        </tr>

                    </table>

                </div>
                <div class="popUpBtn center">
                    <button type="button" class="blue bgnone clear"  onclick="formAct.clearData()"  style="float: left;">全部清空</button>
                    <button type="button" class="blue bgnone clear"  onclick="formAct.selectDelData()"  style="float: left;">批量删除</button>
                    <button type="button" class="blue bgnone close">关闭</button>
                    <button type="button" class="bluebg white" lay-submit lay-filter="submit">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 公共配置第三方组件 -->
<script type="text/javascript">
    layui.config({
        version: false,
        debug: false,
        base: "${re.contextPath}/plugin/layui/lay/modules/"
    })
</script>

<script>
    var layer;
    var form;
    var laydate;
    var tableSelect;
    var upload;
    var uploadListIns;
    var htlistJson = '${htlistJson}';
    var htList ;
    var htCount = 0;
    var htObjList = [];
    var formAct;
    layui.use(['form', 'laydate', 'layer', 'upload','tableSelect'], function () {
        layer = layui.layer;
        form = layui.form;
        laydate = layui.laydate;
        upload = layui.upload;
        tableSelect = layui.tableSelect;
        formAct = {
            init: function(){
                //初始化:
                //把后端的双重数组转换对对象数组
                formAct.formatData();
                formAct.showItem();

            },
            //把后端的双重数组转换对对象数组
            formatData: function(){
                if(htlistJson){
                    htList = JSON.parse(htlistJson);
                    if(htList){
                        htCount = htList.length;
                        for(var a=0;a<htList.length;a++){
                            var aList = [];
                            aList = htList[a];
                            var aObj = {};
                            for(var b=0;b<aList.length;b++){
                                if(b == 0){
                                    aObj.id=aList[b];
                                    aObj.ind = aList[b];
                                }
                                if(b == 1){
                                    aObj.qyname = aList[b];
                                }
                                if(b == 2){
                                    aObj.mingcheng = aList[b];
                                }
                                if(b == 3){
                                    aObj.pinpai = aList[b];
                                }
                                if(b == 4){
                                    aObj.xinghao = aList[b];

                                }
                                if(b == 5){
                                    aObj.shuliang = aList[b];
                                }
                                if(b == 6){
                                    aObj.danwei = aList[b];
                                }
                            }
                            htObjList.push(aObj);
                        }
                    }
                }
            },
            showItem: function(){
                if(htObjList && htObjList.length>0){
                    for(var a=0;a<htObjList.length;a++){
                        //20210815 页面一开始不加载全部的数量
                       // formAct.addOneLine(htObjList[a]);
                    }
                }
            },
            clearData:function(){
                //清空数据
                var _tb = $("#tabledata").find("tbody");
                _tb.find("tr").remove();

            },
            selectDelData:function(){
                var _tb = $("#tabledata").find("tbody");
                var  selectCount=0;
                $("[type=checkbox]:checked").each(function(i,v){
                        selectCount++;
                })
                if(selectCount==0){
                    layer.msg('请选中后再操作',{icon:2});
                    return ;
                }else{
                    $("[type=checkbox]:checked").each(function(i,v){
                            $(v).parents("tr").remove();
                    })
                }

            },
            addOneLine: function(data){
                var _tb = $("#tabledata").find("tbody");
                var _tr_cnt = _tb.find("tr").length + 1;
                var ind = '';
                var id;
                if(data && data.ind){
                    ind = data.ind;
                    id = data.ind;
                }else{
                    id = formAct.getId();
                }
                var qyname = '';
                if(data && data.qyname){
                    qyname = data.qyname;
                }
                var mingcheng = '';
                if(data && data.mingcheng){
                    mingcheng = data.mingcheng;
                }
                var pinpai = '';
                if(data && data.pinpai){
                    pinpai = data.pinpai;
                }
                var xinghao = '';
                if(data && data.xinghao){
                    xinghao = data.xinghao;
                }
                var shuliang = '';
                if(data && data.shuliang){
                    shuliang = data.shuliang;
                }
                var danwei = '';
                if(data && data.danwei){
                    danwei = data.danwei;
                }
                _tb.append('<tr>'+
                    '<td style="width: 5%; border: 1px solid #CCCCCC;" align="center">'+
                     '<input type="checkbox"  name=\'checkbox\'  style="display:block;">'+
                    '</td>'+
                    '<td style="width: 5%; border: 1px solid #CCCCCC;" align="center">'+
                    '<input align="center" type="text" class="fdata" value="'+ind+'" style="text-align: center" name="formDataList['+ind+'].data1" iname="data1">'+
                    '<input type="hidden" class="fdata" name="formDataList['+ind+'].tableRow" iname="tableRow" value="7">'+
                    '<input type="hidden" class="fdata" name="formDataList['+ind+'].tableCos" iname="tableCos" value="10">'+
                    '<input type="hidden" class="fdata" name="formDataList['+ind+'].tableIndex" iname="tableIndex" value="1">'+
                    '</td>'+
                    '<td style="width: 10%; border: 1px solid #CCCCCC;">'+
                    '<input id="qyname'+ind+'" type="text" class="fdata qyname-input" style="text-align: center" name="formDataList['+ind+'].data2" iname="data2" value="'+qyname+'" readonly="readonly">'+
                    '</td>'+
                    '</td>'+
                    '<td style="width: 10%; border: 1px solid #CCCCCC;">'+
                    '<input id="mingcheng'+ind+'"  placeholder="请选择"  type="text" class="fdata mingcheng-input" style="text-align: center" name="formDataList['+ind+'].data3" iname="data3" value="'+mingcheng+'" readonly="readonly">'+
                    '</td>'+
                    '<td style="width: 10%; border: 1px solid #CCCCCC;"> ' +
                    '<input type="text" class="fdata" style="text-align: center" name="formDataList['+ind+'].data4" iname="data4" value="'+pinpai+'" readonly="readonly">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;">'+
                    '<input type="text" class="fdata" style="text-align: center" name="formDataList['+ind+'].data5" iname="data5" value="'+xinghao+'" readonly="readonly">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;">'+
                    '<input type="text" class="fdata" name="formDataList['+ind+'].data6" style="text-align: center" iname="data6" value="'+shuliang+'" readonly="readonly">'+
                    '</td>'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;">'+
                    '<input type="text" class="fdata" name="formDataList['+ind+'].data7" style="text-align: center" iname="data7" value="'+danwei+'" readonly="readonly">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;" align="center">'+
                    '<input type="text" class="fdata" name="formDataList['+ind+'].data8" style="text-align: center" iname="data8">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;" align="center">'+
                    '<input type="text" class="fdata" name="formDataList['+ind+'].data9" style="text-align: center" iname="data9">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;" align="center">'+
                    '<input type="text" class="fdata" name="formDataList['+ind+'].data10" style="text-align: center" iname="data10">'+
                    '</td>'+
                    '<td style="width: 10%;border: 1px solid #CCCCCC;" align="center">'+
                    '<img src="${re.contextPath}/plugin/common/images/19@2x.png" style="width: 40px;" class="del-img" alt="">'+
                    '</td>'+
                    '</tr>');
                formAct.reNameList();
                formAct.bindDel();
                formAct.bindSelect();

            },
            getId: function(){
                return Date.now()+(Math.random()*1000000).toString().substr(0,3);
            },reNameList: function(){
                $("#tabledata").find("tbody").find("tr").each(function (i, v) {
                    var _v_tr = $(v);
                    _v_tr.find(".fdata").each(function (j, w) {
                        var _v_input = $(w);
                        _v_input.attr("name", "formDataList[" + i + "]." + _v_input.attr("iname"));
                        if(_v_input.hasClass('mingcheng-input')){
                            _v_input.attr('id','mingcheng'+i);
                        }
                    })
                })
            },
            bindDel: function(){
                $(".del-img").on('click',function(){
                    $(this).parent().parent().remove();
                    formAct.reNameList();
                })
            },
            bindSelect: function(){
                $.each($(".mingcheng-input"),function(ind,e){
                    var id = $(e).attr('id');
                    var oldValue = $(e).val();
                    tableSelect.render({
                        elem: "#"+id,	//定义输入框input对象 必填
                        checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
                        // searchKey: 'keyword',	//搜索输入框的name值 默认keyword
                        searchPlaceholder: '关键词搜索',	//搜索输入框的提示文字 默认关键词搜索
                        table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                            data: htObjList,
                            cols: [[
                                {type: 'checkbox'}
                                ,{field: 'id',hide: true}
                                ,{field: 'ind', title: '序号',align: 'center'}
                                ,{field: 'qyname', title: '区域',align: 'center'}
                                ,{field: 'mingcheng', title: '名称',align: 'center'}
                                ,{field: 'pinpai', title: '品牌',align: 'center'}
                                ,{field: 'xinghao', title: '型号',align: 'center'}
                                ,{field: 'shuliang', title: '数量',align: 'center'}
                                ,{field: 'danwei', title: '单位',align: 'center'}
                            ]]
                        },
                        done: function (elem, data) {
                            var NEWJSON = [];
                            layui.each(data.data, function (index, item) {
                                // NEWJSON.push(item.1)
                                //选中的为item:
                                //选中的物料名称:
                                if(formAct.checkAlreadyHave(item)){
                                    layer.msg('已经存在的材料',{icon:2});
                                    return ;
                                }else{
                                    //赋值:
                                    if(index==0){
                                        var _tb = $("#tabledata").find("tbody");
                                        var _tr = $(e).parents('tr');
                                        console.log($(e));
                                        _tr.find("td:eq(0) input[type=text]").val();
                                        _tr.find("td:eq(1) input[type=text]").val(item.ind);
                                        _tr.find("td:eq(2) input[type=text]").val(item.qyname);
                                        _tr.find("td:eq(3) input[type=text]").val(item.mingcheng);
                                        _tr.find("td:eq(4) input[type=text]").val(item.pinpai);
                                        _tr.find("td:eq(5) input[type=text]").val(item.xinghao);
                                        _tr.find("td:eq(6) input[type=text]").val(item.shuliang);
                                        _tr.find("td:eq(7) input[type=text]").val(item.danwei);
                                    }else{
                                        formAct.addOneLine(item);
                                    }

                                    // elem.val(item.mingcheng);
                                }
                            })

                        }
                    })
                })
            },
            checkAlreadyHave: function(item){
                //获取table中的值:
                var _tb = $("#tabledata").find("tbody");
                var _tr = _tb.find("tr");
                if(_tr && _tr.length>0){
                    for(var a=0;a<_tr.length;a++){
                        var sameCount = 0;
                        var currTr = $(_tr[a]);
                        var oldQyname = currTr.find("td:eq(2) input[type=text]").val();
                        if(oldQyname && oldQyname == item.qyname){
                            sameCount = sameCount + 1;
                        }
                        var oldMingcheng = currTr.find("td:eq(3) input[type=text]").val();
                        if(oldMingcheng && oldMingcheng == item.mingcheng){
                            sameCount = sameCount + 1;
                        }
                        var oldPinpai = currTr.find("td:eq(4) input[type=text]").val();
                        if(oldPinpai && oldPinpai == item.pinpai){
                            sameCount = sameCount + 1;
                        }
                        var oldGuige = currTr.find("td:eq(5) input[type=text]").val();
                        if(oldGuige && oldGuige == item.xinghao){
                            sameCount = sameCount + 1;
                        }
                        if(sameCount == 4){
                            return true;
                        }
                    }
                }
            }


        }


        // 日期
        laydate.render({
            elem: '#spfF4',
            value: new Date(),
            trigger: 'click',
            format: 'yyyy年MM月dd日'
        });
        // 表单校验
        //$('form').initVerify(form);
        //监听提交
        form.on('submit(submit)', function (data) {
            layerAjax('/supervisor/projectManager/addFormFile', data.field, '', function (d) {
                if (d.flag == true) {
                    var spfId = d.data.spfId;// fmid
                    var fpid = d.data.fpid;// fpid
                    POBrowser.openWindowModeless('/sys/office/openword?ft=2&fmid=' + spfId + '&fpid=' + fpid, 'width=1200px;height=800px;', '{}')
                } else {
                    layer.msg(d.msg, {icon: 2});
                }
            });
            return false;
        });
        $('.close').click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        form.render();
        formAct.init();
    });
</script>
</body>
</html>
